package com.msw.rest;

import com.msw.rest.common.constant.RestType;
import com.msw.rest.service.jersey.UserResources;
import jersey.repackaged.com.google.common.collect.Maps;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.servlet.GrizzlyWebContainerFactory;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.servlet.ServletContainer;

import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by hadoop on 16-12-2.
 */
public class RestApp {
    private static final URI BASE_URI = URI.create(RestType.BASE_URL);

    public static final String ROOT_PATH = RestType.ROOT_PATH;

    public static void main(String[] args) {
        try {

            Map<String, String> initParams = Maps.newHashMap();
            initParams.put(ServerProperties.PROVIDER_PACKAGES, UserResources.class.getPackage().getName());

            // ServletContainer, start httpserver
            final HttpServer server =
                    GrizzlyWebContainerFactory.create(BASE_URI, ServletContainer.class, initParams);

            System.out.println(String.format("Application started.%nTry out %s%s%nHit enter to stop it...",
                    BASE_URI, ROOT_PATH));

            System.in.read();
            server.shutdownNow();
        } catch (IOException ex) {
            Logger.getLogger(RestApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
